package com.china08.yxyapi.rabbitmq.listener.statistics;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.china08.yxyapi.config.RabbitConfig;
import com.china08.yxyapi.service.res.statistics.impl.ResourceStatisticsImpl;

/**
 * 备授课系统,pv统计,采纳了统计
 *
 */
@Component
@EnableRabbit
public class ResourceReportListener {

	public static final Logger LOGGER = LoggerFactory.getLogger(ResourceReportListener.class);

	@Autowired
	private ResourceStatisticsImpl resourceStatisticsImpl;

	/**
	 * @param 统计资源,地区的每日变化
	 */
	@RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_AREA)
	private void areaStatistics(Integer date) {
		resourceStatisticsImpl.areaStatistics(date);
	}

	/**
	 * @param date
	 *            统计资源, 学校资源的总数
	 */
	@RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL)
	private void schoolStatistics(Integer date) {
		resourceStatisticsImpl.schoolStatistics(date);
	}

	/**
	 * 统计学校资源总数, 使用mq统计区间段.
	 * 
	 * @param beginDate
	 * @param endDate
	 */
	@RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_TOTAL)
	private void schoolStatisticsTotal(String beginDateAndEndDate) {
		String[] beginToEnd = beginDateAndEndDate.split("-");
		if (beginToEnd != null && beginToEnd.length == 2) {
			resourceStatisticsImpl.schoolStatisticsTotal(Integer.parseInt(beginToEnd[0]),
					Integer.parseInt(beginToEnd[1]));
		}

	}

	/**
	 * @param date
	 *            统计资源, 每天 学校资源的总数
	 */
	@RabbitListener(queues = RabbitConfig.YW_STATISTICS_RESOURCE_SCHOOL_DAY)
	private void schoolStatisticsForDay(Integer date) {
		resourceStatisticsImpl.schoolStatisticsForDay(date);
	}

	/**
	 * @param date
	 *            统计资源, 用户上传与分享资源
	 */
	@RabbitListener(queues = RabbitConfig.YW_USER_RESOURCE_STATISTICS_MONTH)
	private void userStatisticsForMonth(Integer monthOfYear) {
		resourceStatisticsImpl.userStatisticsForMonth(monthOfYear);
	}
}
